home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Disk / moni / FileX-src.lha / FileX-src / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-16  |  4.7 KB  |  204 lines

  1. #include <devices/printer.h>
  2.  
  3. #include "FileXStructs.h"
  4. #include "FileXStrings.h"
  5.  
  6. #include "allprotos.h"
  7.  
  8. union printerIO
  9. {
  10.     struct IOStdReq ios;
  11.     struct IODRPReq iodrp;
  12.     struct IOPrtCmdReq iopc;
  13. };
  14.  
  15. void MyPrint(UBYTE *start, long laenge, long DisplayTyp, struct Window *Wnd )
  16. {
  17.     struct MsgPort *PrinterMP;
  18.     union printerIO *PrintIO;
  19.     
  20.     if( !laenge )
  21.     {
  22.         DisplayLocaleText( MSG_INFO_PRINT_NOTHINGTOPRINT );
  23.     }
  24.     else
  25.     if(PrinterMP=CreateMsgPort())
  26.     {
  27.         if(PrintIO=(union printerIO *) CreateExtIO(PrinterMP,sizeof(union printerIO)))
  28.         {
  29.             if(0==OpenDevice("printer.device",0L,(struct IORequest *)PrintIO,0))
  30.             {
  31.                 UWORD status;
  32.  
  33.                 PrintIO->ios.io_Data=&status;
  34.                 PrintIO->ios.io_Command=PRD_QUERY;
  35.  
  36.                 DoIO((struct IORequest *)PrintIO);
  37.  
  38.                     /* Prüfen, ob Drucker bereit */
  39.                     /* Endweder Parallel und nicht offline oder seriell */
  40.  
  41.                 if( ((PrintIO->ios.io_Actual==1)&&(!(status&0x300)))
  42.                     || (PrintIO->ios.io_Actual!=1))
  43.                 {
  44.                     BOOL RequesterOpened = FALSE;
  45.                 
  46.                         /* Reqtoolsrequesterdaten */
  47.                 
  48.                     struct rtHandlerInfo *hinfo;
  49.                 
  50.                         /* Intuitionrequesterdaten */
  51.                 
  52.                     struct Window *ReqWnd;
  53.                     struct EasyStruct Easy;
  54.         
  55.                         /* Requester öffnen */
  56.                 
  57.                     if( UseAsl )
  58.                     {
  59.                             /* Werte für den Intuitionrequester setzen */
  60.  
  61.                         Easy.es_StructSize = sizeof(struct EasyStruct);
  62.                         Easy.es_Flags = NULL;
  63.                         Easy.es_Title = GetStr( MSG_WINDOWTITLE_INFO );
  64.                         Easy.es_GadgetFormat    = GetStr( MSG_GADGET_STOPPRINTING );
  65.                         Easy . es_TextFormat = GetStr( MSG_INFO_PRINT_PRINTING );
  66.  
  67.                         if( ReqWnd = BuildEasyRequest( Wnd, &Easy, NULL ))
  68.                             RequesterOpened = TRUE;
  69.                     }
  70.                     else
  71.                     {
  72.                         if(CALL_HANDLER == rtEZRequestTags(GetStr(MSG_INFO_PRINT_PRINTING), GetStr(MSG_GADGET_STOPPRINTING), 0L, 0L, RTEZ_ReqTitle, GetStr( MSG_WINDOWTITLE_INFO ), (LONG)RT_ReqHandler, (LONG)&hinfo,  Wnd ? RT_Window : TAG_IGNORE, Wnd, RT_Underscore, '_', TAG_DONE))
  73.                             RequesterOpened = TRUE;
  74.                     }
  75.                 
  76.                     if( RequesterOpened )
  77.                     {
  78.                         register short zeichen = 16;
  79.                         ULONG sigs;
  80.                         LONG off=0,k;
  81.                         UBYTE buffer[9+1+35+1+16+2];
  82.  
  83.                         PrintIO->ios.io_Length=-1;
  84.                         PrintIO->ios.io_Data="\033#1";
  85.                         PrintIO->ios.io_Command=CMD_WRITE;
  86.         
  87.                         DoIO((struct IORequest *)PrintIO);
  88.  
  89.  
  90.                         buffer[9]=buffer[18]=buffer[27]=buffer[36]=buffer[45]=' ';
  91.                         buffer[62]='\n';
  92.  
  93.                         if(laenge-off<0)zeichen=off-laenge;
  94.  
  95.                         sprintf(buffer,"%08.lx: ",off);
  96.  
  97.                         for(k=0;k<zeichen;k++)
  98.                         {
  99.                             ByteToString(start[off+k],buffer+2*k+k/4+10);
  100.                             buffer[k+10+36]=displaytab[DisplayTyp][start[k+off]];
  101.                         }
  102.  
  103.                         PrintIO->ios.io_Length=63;
  104.                         PrintIO->ios.io_Data=buffer;
  105.                         PrintIO->ios.io_Command=CMD_WRITE;
  106.         
  107.                         SendIO((struct IORequest *)PrintIO);
  108.  
  109.                         off+=16;
  110.  
  111.                         while( RequesterOpened && ( off < laenge ))
  112.                         {
  113.                             if(!UseAsl)
  114.                             {
  115.                                 if(!hinfo->DoNotWait)
  116.                                     sigs = Wait (hinfo->WaitMask|(1L<< PrinterMP->mp_SigBit));
  117.                             }
  118.                             else
  119.                                 sigs = Wait ( 1L<< PrinterMP->mp_SigBit );
  120.  
  121.                             if(sigs&(1L << PrinterMP->mp_SigBit))
  122.                             {
  123.                                 while(GetMsg(PrinterMP));
  124.  
  125.                                 zeichen = 16;
  126.                                 if(laenge-off-16<0)zeichen=laenge-off;
  127.  
  128.                                 sprintf(buffer,"%08.lx: ",off);
  129.  
  130.                                 for(k=0;k<zeichen;k++)
  131.                                 {
  132.                                     ByteToString(start[off+k],buffer+2*k+k/4+10);
  133.                                     buffer[k+10+36]=displaytab[DisplayTyp][start[k+off]];
  134.                                 }
  135.  
  136.                                 if(zeichen!=16)
  137.                                 {
  138.                                     for(k=zeichen;k<16;k++)
  139.                                     {
  140.                                         *(buffer+2*k+k/4+10)=' ';
  141.                                         *(buffer+2*k+k/4+10+1)=' ';
  142.                                         *(buffer+k+10+36)=' ';
  143.                                     }
  144.                                 }    
  145.  
  146.                                 PrintIO->ios.io_Length=63;
  147.                                 PrintIO->ios.io_Data=buffer;
  148.                                 PrintIO->ios.io_Command=CMD_WRITE;
  149.             
  150.                                 SendIO((struct IORequest *)PrintIO);
  151.  
  152.                                 off+=16;
  153.                             }
  154.  
  155.                             if( UseAsl )
  156.                             {
  157.                                 if( -2 != SysReqHandler( ReqWnd, NULL, FALSE ))
  158.                                     RequesterOpened = FALSE;
  159.                             }
  160.                             else                        
  161.                             {
  162.                                 if( !( CALL_HANDLER == rtReqHandler( hinfo, sigs, TAG_END )))
  163.                                     RequesterOpened = FALSE;
  164.                             }
  165.                         }
  166.  
  167.                         if( UseAsl )
  168.                         {
  169.                             if( ReqWnd )
  170.                                 FreeSysRequest( ReqWnd );
  171.                         }
  172.  
  173.                         if( RequesterOpened )
  174.                         {
  175.                             if( !UseAsl )
  176.                             {
  177.                                 ULONG ret;
  178.  
  179.                                 do
  180.                                 {
  181.                                     ret = rtReqHandler( hinfo, 0L, RTRH_EndRequest, REQ_OK, TAG_END );
  182.                                 } while( ret == CALL_HANDLER );
  183.                             }
  184.  
  185.                             WaitIO((struct IORequest *)PrintIO);
  186.                         }
  187.                         else 
  188.                         {
  189.                             AbortIO((struct IORequest *)PrintIO);
  190.                             WaitIO((struct IORequest *)PrintIO);
  191.                         }
  192.                     }
  193.                 }
  194.                 else
  195.                     DisplayLocaleText(MSG_INFO_PRINT_PRINTERNOTREADY);
  196.  
  197.                 CloseDevice((struct IORequest *)PrintIO);
  198.             }
  199.             DeleteExtIO((struct IORequest *)PrintIO);
  200.         }
  201.         DeleteMsgPort(PrinterMP);
  202.     }
  203. }
  204.